package com.demo.gmall.service.impl;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.dubbo.rpc.cluster.LoadBalance;
import com.demo.gmall.bean.UserAddress;
import com.demo.gmall.service.OrderService;
import com.demo.gmall.service.UserService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 1.将服务提供者注册到注册中心
 * 2.让服务消费者去注册中心订阅服务提供者的服务
 */
@Service
public class OrderServiceImpl implements OrderService {

    @Reference
    UserService userService;

    @HystrixCommand(fallbackMethod = "hello")
    public void initOrder(String userId) {
        List<UserAddress> userAddressList = userService.getUserAddressList(userId);
        for (UserAddress address : userAddressList) {
            System.out.println(address.getUserAddress());
        }
    }

    public void hello(String userId) {
        System.out.println("hello");
    }
}
